package top.shmly.universal.utils;

import org.springframework.util.StringUtils;
import top.shmly.universal.utils.impl.DateUtilsImpl;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: Jibny
 * @time: 2020.04.25 下午11:13
 */

public interface DateUtils {
    String getFirstDayOfMonth(int year, int month);

    String getLastDayOfMonth(int year, int month);

    String getFirstDayOfYear(int year);

    String getLastDayOfYear(int year);

    /**
     * 获取当前月第一天
     *
     * @return
     */
    String firstDayOfCurrentMonth();

    /**
     * 获取当前月最后一天
     *
     * @return
     */
    String lastDayOfCurrentMonth();


    String compareDate(String firstDate, String lastDate);

    Date getNextDay(Date date);

    /**
     * 获取日期的月份
     *
     * @param date
     * @return
     */
    String getMonth(Date date);

    /**
     * 使用用户格式格式化日期
     *
     * @param date
     * @param pattern
     * @return
     */
    String format(Date date, String pattern);

    /**
     * 比较两个日期大小
     *
     * @param DATE1
     * @param DATE2
     * @param format 格式 yyyy-MM-dd,yyyy-MM-dd hh:mm:ss
     * @return
     */
    int compareDate(String DATE1, String DATE2, String format);

    static void main(String[] args) {
        DateUtils dateUtils = DateUtilsImpl.getInstance();
        System.out.println(dateUtils.firstDayOfCurrentMonth());
        System.out.println(dateUtils.lastDayOfCurrentMonth());
        String camStartDate = "2016-11-11";
        String camEndDate = "2019-11-11";
        List<String> years = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date d1 = sdf.parse(camStartDate);
            Date d2 = sdf.parse(camEndDate);
            Calendar c = Calendar.getInstance();
            c.setTime(d1);
            int year1 = c.get(Calendar.YEAR);
            c.setTime(d2);
            int year2 = c.get(Calendar.YEAR);
            do {
                if (year1 >= 2017) {
                    years.add(year1 + "");
                }
                year1++;
            } while (year2 >= year1);

        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println(years);
    }

    /**
     * 传入月份，将period转换为MM的格式
     *
     * @param period
     * @return
     */
    String getMonthTwoPlace(String period);

    /**
     * 将日期字符串转化为Date类型
     *
     * @param dateStr
     * @param pattern
     * @return
     */
    Date StringToDate(String dateStr, String pattern);

    /**
     * 将日期转化为字符串类型
     *
     * @param date
     * @param pattern
     * @return
     */
    String dateToString(Date date, String pattern);
}
